package Dao.impl;

import Dao.UserDao;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import pojo.Admin;
import utils.DruidUtils;

import java.sql.SQLException;


/**
 * @author LiangHaiBo
 * @version 1.0
 * @date 2021.8.27 下午 16:09
 */
public class UserDaoimpl  implements UserDao {
    @Override
    public void Regis(String name,String password) {
        try {
            QueryRunner qr = new QueryRunner(DruidUtils.getDataSourse());
            String sql = "insert into Admin (name,password) values (?,?)";
            qr.update(sql,name,password);
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }

    @Override
    public Admin selectUserByName(String name) {

        try {
            QueryRunner qr = new QueryRunner(DruidUtils.getDataSourse());

            String sql = "select * from Admin where name =? ";

            Admin admin = qr.query(sql, new BeanHandler<Admin>(Admin.class), name);
            return  admin;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
}
